package com.htht.smartschool.action.position;

import java.util.List;
import java.util.Map;

import com.htht.smartschool.action.baseaction.BaseAction;
import com.htht.smartschool.common.model.ParamData;
import com.htht.smartschool.common.servlet.DataContainer;
import com.htht.smartschool.model.position.PositionData;
import com.htht.smartschool.model.position.PositionProtoBuffer;
import com.htht.smartschool.model.position.PositionProtoBuffer.msgInfo.Builder;
import com.htht.smartschool.service.position.PositionService;
import com.htht.smartschool.util.system.GsonUtils;

public class PositionAction extends BaseAction{

	@SuppressWarnings("rawtypes")
	@Override
	public boolean processData(DataContainer obj, ParamData pd) {
		boolean flag = false;
		PositionService positionService = new PositionService();
		PositionData positionData = (PositionData) GsonUtils.getInstance().fromJson(pd.getData(), PositionData.class);
		if(pd.getCmd().equalsIgnoreCase("getHistoryPositionByStudentCode")){
			List<PositionData> list = positionService.getHistoryPositionByStudentCode(positionData.getStudentcode(),positionData.getStartTime(),positionData.getEndTime(),positionData.getUsertype());
			if(list.size() >= 0){
				flag = true;
				obj.setData(list);
			}else{
				obj.setData("查无数据！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getPositionByStudentCode")){
			PositionData position = positionService.getPositionByStudentCode(positionData.getStudentcode());
			if(position != null){
				flag = true;
				obj.setData(position);
			}else{
				obj.setData("查无数据！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateByStudentCode")){
			PositionData position = positionService.updateByStudentCode(positionData);
			if(position != null){
				flag = true;
				obj.setData(position);
			}else{
				obj.setData("更新学生位置失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("teacherGetStudentsPosition")){
			List<PositionData> positions = positionService.teacherGetStudentsPosition(positionData);
			if(positions.size() > 0){
				flag = true;
				obj.setData(positions);
			}else{
				obj.setData("查无数据！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getSosWarn")){
			Map positions = positionService.getSosWarn(positionData);
			if(positions!= null){
				flag = true;
				obj.setData(positions);
			}else{
				obj.setData("查无数据！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("addSosWarn")){
			PositionProtoBuffer.msgInfo.Builder positionprotobuffer = (Builder) GsonUtils.getInstance().fromJson(pd.getData(), PositionProtoBuffer.msgInfo.Builder.class);
			boolean result = positionService.addSosWarn(positionprotobuffer);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("添加失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateSosWarn")){
			boolean result = positionService.updateSosWarn(positionData);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("添加失败！");
			}
		}
		return flag;
	}

}
